//到货通知单
$(function(){
	$('#emsDatagrid').datagrid({
		//url:getarrivalUrl+"?randnum="+Math.floor(Math.random()*1000000),
		url:getarrivalUrl,
		title:'快递公司列表',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[1,2,5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'code',title:'公司编号',sortable:true},
		{field:'name',title:'公司名称'},
		{field:'url',title:'域名URL'},
		{field:'weight',title:'重量段(kg)'},
		{field:'merchant_code',title:'商家编码(多个用半角,分割)'},
		{field:'text',title:'备注',width:100,
				formatter: function(value,row,index){    
				   return '<span title="'+value+'">'+value+'</span>'    
				}
		},
		{field:'default_status',title:'是否是默认',sortable:true,
				formatter: function(value,row,index){
					if(value==1){
						return "是";
					}else{
						return "否";
					}  
				}
		},
		{field:'add_time',title:'添加时间',sortable:true},
		{field:'update_time',title:'更新时间',sortable:true},
		{field:'examine_time',title:'审核时间',sortable:true},
		{field:'status',title:'审核状态',sortable:true}
		]],
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
emsObj={
	add:function(url){
		$('#emsAddForm').form('submit',{
			url:url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	var result=eval('('+result+')');
                if(!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#emsAddDialog').dialog('close');  
                    });
                }else{
					$.messager.alert('提示信息',result.message,'info',function(r){
                    	$('#emsAddDialog').dialog('close');       
						$('#emsDatagrid').datagrid('reload'); 
                    });
                }
            },
		});
	},
	save:function(url){
		$('#emsEditForm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	 var result=eval('('+result+')');
                if (!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#emsEditDialog').dialog('close');
                    });
                }else{
                    $('#emsEditDialog').dialog('close');      
                    $('#emsDatagrid').datagrid('reload');    
                }
            }
        });
	},
	showAll:function(){
		$('#emsDatagrid').datagrid({ queryParams:''});
	},
	infoBar:function(){//查看账册
		var Row=$('#emsDatagrid').datagrid('getSelections');
        if (Row.length>1){
            $.messager.alert('提示','一次只能查看一条记录!','info');
        }else if(Row.length==1){
			var id=Row[0]['id'];
        	window.parent.showTab(emsfeeUrl,'费用模板',id);
        }else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	addBar:function(){
		$('#emsAddDialog').dialog('open').dialog('setTitle','添加');
		$('#emsAddForm').form('clear');
	},
	editBar:function(){
		var emsRow=$('#emsDatagrid').datagrid('getSelections');
        if (emsRow.length>1){		            	
            $.messager.alert('提示','一次只能修改一条记录!','info');
        }else if(emsRow.length==1){            	
        	$('#emsEditDialog').dialog('open').dialog('setTitle','编辑用户');
            $('#emsEditForm').form('load',emsRow[0]);
        }else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	removeBar:function(){
		var emsRow=$('#emsDatagrid').datagrid('getSelections');
        if (emsRow.length>0){
        	$.messager.confirm('删除提示','真的要删除这'+emsRow.length+'个信息吗?',function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<emsRow.length;i++){
                		ids.push(emsRow[i].id);
                	}
                	var id=ids.join(',');
                    $.post(emsDelUrl,{id:id},function(result){
                        if (result.status){
							$.messager.alert('提示信息',result.message,'info',function(r){
								$('#emsAddDialog').dialog('close');       
								$('#emsDatagrid').datagrid('reload'); 
							});
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	examineBar:function(value){
		var emsRow=$('#emsDatagrid').datagrid('getSelections');
		if(value==1){
			var text='确定审核通过吗！';
		}
		if(value==2){
			var text='确定审核不通过吗！';
		}
        if (emsRow.length>0){
        	$.messager.confirm('审核提示',text,function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<emsRow.length;i++){
                		ids.push(emsRow[i].id);
                	}
                	var id=ids.join(',');
                    $.post(examineUrl,{id:id,value:value},function(result){
                        if (result.status){
                            $('#emsDatagrid').datagrid('reload');
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	excelBar:function(){
		var emsRow=$('#emsDatagrid').datagrid('getSelections');
		if (emsRow.length>1){
			$.messager.alert('提示','一次只能选择一条记录','error');
		}else if(emsRow.length==1){
			emsid=emsRow[0]['id'];
			var index=layer.open({
				type: 2,
				title: '导入费用模板',
				shadeClose: true,
				shade: 0.5,
				offset:['180px'],
				area: ['1020px', '135px'],
				content: excelUrl
			});
		}else{
			$.messager.alert('提示','请选择列表数据','error');
		}
			
		
	}
}